var loadingobj;
var PhotoClipObj = new PhotoClip('#clipArea', {
    size: [260, 260],
    outputSize: 800,
    file: '#file',
    view: '.photo-previews',
    ok: '#clipBtn',
    //img: 'img/mm.jpg',
    loadStart: function() {
        loadingobj = bottlecms.loading("载入中…");
        $(".clipbox").show();
        console.log('开始读取照片');

    },
    loadComplete: function() {
        loadingobj.close();
        console.log('照片读取完成');
        setTimeout(function(){
            PhotoClipObj.scale(0);
        },100)            },
    done: function(dataURL) {
        $(".clipbox").hide();
        $(".upfilebox .btn").text("重新上传");
        console.log(dataURL);

        uploadfilebase64(dataURL)
    },
    fail: function(msg) {
        bottlecms.toast(msg);
    }
});


$(document).on('click', '.clipbox .cancel', function(event) {
    event.preventDefault();
    $(".clipbox").hide();
});


function uploadfilebase64(file,refun){
    var loadingobj = bottlecms.loading('上传中…');
    bottlecms.post( "/m/ajax/common/upload_blob",{ base64file:file,filedir:'bc_head_img'},function(rdata){
        loadingobj.close();
        if(rdata.obj){
            updata_single_photo_fun(rdata.obj,function(data){
                bottlecms.toast("上传成功");
            });
            refun && refun();
        }else{
            bottlecms.toast("上传失败");
        }
    },function(rerr){
        loadingobj.close();
        bottlecms.toast(rdata.msg);
    })
}